package com.gaohe;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gaohe.mapper.UserMapper;
import com.gaohe.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;
import java.util.PriorityQueue;
import java.util.UUID;

@SpringBootTest(classes = Application.class)
public class MpTest01 {
    @Autowired
    private UserMapper mapper;

    @Test
    public void getAll(){
        List<User> userList = mapper.selectList(null);
        System.out.println(userList);
    }
    //新增
    @Test
    public void save(){
        UUID uuid = UUID.randomUUID();
        System.out.println(uuid.toString());
        User user = new User();
        user.setName("jiangxiang");
        user.setPass("kai");
        user.setAge(18);
        user.setTel("22222222222");
        int res = mapper.insert(user);
        //主键返回  订单  订单详情
        System.out.println(user);
        System.out.println("res = " + res);
    }
    @Test
    public void modify(){
        User user = new User();
        user.setId(1535725570L);
        user.setName("xiang");
        int res = mapper.updateById(user);
        System.out.println("res = " + res);
    }
    //删
    @Test
    public  void  deleteById(){
        mapper.deleteById(881340417);
    }
    //分页查询
    @Test
    public void page(){
        //1.创建分页对象 limit x,x  //2.设置 分页数据
        Page<User> page = new Page<>(1, 3);
        //3.查询  获取数据
        mapper.selectPage(page,null);
        //1.分页数据
        System.out.println("分页数据 = " + page.getRecords());
        //2.当前页码
        System.out.println("当前页码 = " +page.getCurrent());
        //3.总页数
        System.out.println("总页数 = " +page.getPages());
        //4.每页展示条目数
        System.out.println("每页展示条目数 = " +page.getSize());
        //5.总条目数
        System.out.println("总条目数 = " +page.getTotal());
    }
}
